﻿using Common.Log;
using DryWCS.App.Common;
using DryWCS.Model.Conveyor;
using DryWCS.Model.Enum;
using DryWCS.Model.Stacker;
using DryWCS.Service.Conveyor;
using DryWCS.Service.Stacker;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DryWCS.App.ViewModel.Tasks
{
    public class AddConveyorTaskViewModel: ViewModelBase
    {
        #region Parameter
        string msg = null;
        ConveyorService conveyorService = new ConveyorService();
        public ConveyorTaskModel model;

        public ConveyorTaskModel Model
        {
            get { return model; }
            set
            {
                model = value;
                this.RaisePropertyChanged("Model");
            }
        }
        #endregion

        #region Command
        private RelayCommand addTaskCommand;
        public RelayCommand AddTaskCommand
        {
            get
            {
                if (addTaskCommand == null)
                {
                    addTaskCommand = new RelayCommand(AddTask);
                }
                return addTaskCommand; ;
            }
            set { addTaskCommand = value; }
        }

        #endregion

        private void AddTask()
        {
            msg = Check();
            if (msg != null)
            {
                Msg.Info(msg);
                return;
            }

            Model.CreateTime = DateTime.Now;
            Model.Status = TaskStatusEnum.未执行;
            
           
            if (conveyorService.Insert(Model))
            {
                msg = $"任务Id{Model.Id},任务类型{Model.TaskType},输送车{Model.ConveyorCarCode} 添加成功";
            }
            else
                msg = $"任务Id{Model.Id},任务类型{Model.TaskType},输送车{Model.ConveyorCarCode} 添加失败";
            Msg.Info(msg);
            LogHelper.WriteLog(msg);
        }

        #region 验证
        private string Check()
        {
            string ret = null;
           
            return ret;
        }
        #endregion

        #region Constructor
        public AddConveyorTaskViewModel()
        {
            Model = new ConveyorTaskModel();
        }
        #endregion

    }
}

